package com.javabasic.algorithm.leetcode;

import java.util.Scanner;

/**
 * @Author xiongmin
 * @ClassName BessieWeightProblem
 * @Description TODO
 * @Date 2019/8/31 12:57
 * @Version 1.0
 **/
//public class BessieWeightProblem {
//    static Scanner cin = new Scanner(System.in);
//    static int[] arr;
//    static int h, n, result;
//    public static void main(String[] args) {
//        h = cin.nextInt();
//        n = cin.nextInt();
//        arr = new int[n];
//        for (int i = 0; i < n; i++) {
//            arr[i] = cin.nextInt();
//        }
//        result = h;
//        dfs(h,0);
//        System.out.println(h - result);
//    }
//
//    private static void dfs(int h, int i) {
//        if (h < 0) return;
//        if (h < result) {
//            result = h;
//        }
//        if (i == n) return;
//        dfs(h-arr[i],i+1); // eat
//        dfs(h,i+1); // not eat
//    }
//
//
//}

/**
 * 01背包
 */
public class BessieWeightProblem {

    static Scanner cin = new Scanner(System.in);

    static int[] arr = null, dp = null;
    static int h, n;

    public static void main(String[] args) {
        h = cin.nextInt();
        n = cin.nextInt();

        arr = new int[n];
        dp = new int[h+1];

        for (int i = 0; i < n; i++) {
            arr[i] = cin.nextInt();
        }

        for (int i = 0; i < n; i++) {
            for (int j = h; j >= arr[i]; j--) {
                dp[j] = Math.max(dp[j-arr[i]]+arr[i],dp[j]);
            }
        }
        System.out.println(dp[h]);

    }
}